/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package net.risesoft.risebi.collection.web.admin;

import java.util.List;
import java.util.Map;

import net.risesoft.risebi.collection.model.DataLog;
import net.risesoft.risebi.collection.service.DataLogManager;
import net.risesoft.risebi.collection.web.BaseAction;
import net.risesoft.risebi.commons.struts2extension.Trimable;
import net.risesoft.risebi.commons.util.ExceptionUtil;
import net.risesoft.risebi.commons.util.JSONUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionInvocation;

/**
 *
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Namespace("/admin/DatalogAction")
public class DatalogAction extends BaseAction implements Trimable {
	
	private static final long serialVersionUID = 4321423269583482103L;
	private static Log log = LogFactory.getLog(DatalogAction.class);
	
	@Action(value = "listDatalog", results = { @Result(name = "success", location = "/admin/datalog/datalogList.jsp") })
	public String listDatalog() throws Exception {
		return SUCCESS;
	}
	
	@Action(value = "listComparedValueList", results = { @Result(name = "success", location = "/admin/datalog/comparedValueList.jsp") })
	public String listComparedValueList() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="refreshJson")
	public String refreshJson() throws Exception {
		try {
			if("datalogList".equalsIgnoreCase(this.whichJson)){
				List<DataLog> list = dataLogManager.getDatalogs(node);
				this.json = JSONUtil.getJsonString("include","guid,userName,ip,operateDate,operateType",list);
			}else if("comparedValueList".equalsIgnoreCase(this.whichJson)){
				List<Map<String,String>> list = dataLogManager.getComparedValue(node);
				this.json = JSONUtil.getJsonString(null,null,list);
			}
		} catch (Exception e) {
			log.error(ExceptionUtil.transformException(e));
			this.json = "[]";
		}
		
		return AJAX;
	}

	/* (non-Javadoc)
	 * @see net.risesoft.risebi.commons.struts2extension.Trimable#afterTrim(com.opensymphony.xwork2.ActionInvocation)
	 */
	public void afterTrim(ActionInvocation invocation) {

	}

	/* (non-Javadoc)
	 * @see net.risesoft.risebi.commons.struts2extension.Trimable#preTrim(com.opensymphony.xwork2.ActionInvocation)
	 */
	public boolean preTrim(ActionInvocation invocation) {
		return false;
	}
	
	private DataLogManager dataLogManager;

	public void setDataLogManager(DataLogManager dataLogManager) {
		this.dataLogManager = dataLogManager;
	}
}
